package cn.itsource.org.service.impl;

import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartmentMapper;
import cn.itsource.org.query.DepartmentQuery;
import cn.itsource.org.service.IDepartmentService;
import cn.itsource.base.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void save(Department dept) {
        departmentMapper.save(dept);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(Department dept) {
        departmentMapper.update(dept);
    }

    @Override
    public Department findById(Long id) {
        return departmentMapper.findById(id);
    }

    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    @Override
    public Integer queryCount(DepartmentQuery query) {
        return departmentMapper.queryCount(query);
    }

    @Override
    public PageBean<Department> queryData(DepartmentQuery query) {
        Integer count = departmentMapper.queryCount(query);
        if(count<=0){
            return new PageBean<>();
        }
        List<Department> list = departmentMapper.queryData(query);

        return new PageBean<Department>(count,list);
    }

    @Override
    public void patch(List<Long> ids) {
        departmentMapper.patch(ids);
    }

    @Override
    public List<Department> getDeptTree() {
        return departmentMapper.getDeptTree();
    }
}
